Introduction to Python and Basics
Keywords: Python History, Features, Installation, Variables, Data Types, Operators, Input/Output, Comments
Introduction
Python is one of the most popular high-level programming languages used today. It is known for its simple syntax, readability, versatility, and extensive library support. Python is widely used in web development, artificial intelligence, machine learning, data science, automation, cybersecurity, scientific computing, and software development.
Unlike many programming languages that require complex syntax, Python focuses on code readability, making it an ideal language for beginners as well as professionals.
1. History and Evolution of Python
Python was created by Guido van Rossum at the Centrum Wiskunde & Informatica (CWI), Netherlands.
Guido van Rossum developed Python as a successor to the ABC programming language. The primary objective was to design a language that was easy to learn, powerful, and highly readable.
Timeline of Python Evolution
| Year | Milestone |
|---|---|
| 1989 | Guido van Rossum started developing Python during Christmas holidays |
| 1991 | Python 0.9.0 released |
| 1994 | Python 1.0 introduced functional programming features |
| 2000 | Python 2.0 released with garbage collection and Unicode support |
| 2008 | Python 3.0 released with major improvements |
| 2010–Present | Continuous improvements with regular releases |
Important Milestones
Python 1.0 (1994)
Features included:
Lambda functions
Map()
Filter()
Reduce()
Python 2.0 (2000)
Major additions:
Automatic Garbage Collection
Unicode Support
List Comprehensions
Python 3.0 (2008)
Python 3 was not backward compatible but introduced many improvements:
Better Unicode support
Improved Input/Output
Enhanced syntax
Better exception handling
Faster execution
Today, Python 3.x is the recommended version.
Why was Python Created?
The objectives behind Python were:
Simple syntax
Readable code
Open-source development
Cross-platform compatibility
Object-oriented programming
Rapid application development
2. Features of Python
Python offers numerous powerful features.
1. Easy to Learn
Python uses English-like syntax, making it beginner-friendly.
Example:
print("Hello World")
2. Open Source
Python is freely available under an open-source license.
3. High-Level Language
Python abstracts low-level memory management.
4. Interpreted Language
Python executes code line by line without prior compilation.
5. Platform Independent
Python programs run on:
Windows
Linux
macOS
without modification.
6. Object-Oriented
Supports:
Classes
Objects
Inheritance
Polymorphism
Encapsulation
7. Large Standard Library
Includes modules for:
Mathematics
File Handling
Networking
Data Processing
Web Services
8. Extensible
Python can integrate with:
C
C++
Java
9. Dynamic Typing
Variable types are determined automatically.
x = 10
x = "Python"
10. Rich Community Support
Thousands of libraries are available through PyPI.
3. Applications of Python
Python is used in almost every technology domain.
Web Development
Frameworks:
Django
Flask
FastAPI
Artificial Intelligence
Applications:
Chatbots
Image Recognition
NLP
Robotics
Libraries:
TensorFlow
PyTorch
Keras
Machine Learning
Libraries:
Scikit-Learn
XGBoost
LightGBM
Data Science
Libraries:
Pandas
NumPy
Matplotlib
Seaborn
Automation
Python automates:
Emails
File Management
Data Entry
Web Scraping
Cyber Security
Python is used for:
Network scanning
Ethical hacking
Malware analysis
Desktop Applications
Libraries:
Tkinter
PyQt
Game Development
Framework:
Pygame
Internet of Things (IoT)
Python works with Raspberry Pi and embedded systems.
Cloud Computing
Python supports:
AWS
Azure
Google Cloud
4. Installation and Setup of Python Environment
Several environments are available for Python development.
A. Python IDLE
IDLE stands for Integrated Development and Learning Environment.
Installation Steps
Download Python from the official Python website.
Run the installer.
Select Add Python to PATH.
Click Install.
Launch IDLE.
Advantages:
Lightweight
Beginner-friendly
Comes with Python
B. Anaconda
Anaconda is a Python distribution mainly used for Data Science and Machine Learning.
Installation
Download Anaconda.
Run installer.
Complete installation.
Open Anaconda Navigator.
Features:
Jupyter Notebook
Spyder IDE
Package Manager
Conda Environment
C. Jupyter Notebook
Jupyter provides an interactive notebook interface.
Steps:
pip install notebook
Run:
jupyter notebook
Advantages:
Interactive coding
Markdown support
Visualization
Ideal for Machine Learning
D. Visual Studio Code (VS Code)
VS Code is one of the most popular code editors.
Installation:
Install VS Code.
Install Python.
Install Python Extension.
Select Python Interpreter.
Start coding.
Advantages:
Intelligent code completion
Debugging
Git integration
Extensions
5. Python Syntax and Indentation
Python uses indentation instead of braces.
Example:
if 10 > 5:
print("Correct")
Incorrect:
if 10 > 5:
print("Correct")
Indentation usually consists of 4 spaces.
6. Variables
Variables store data values.
Example:
name = "John"
age = 22
salary = 45000
Python does not require variable declaration.
Variable Naming Rules
✔ Letters
✔ Numbers (not first)
✔ Underscore
✔ Case-sensitive
Valid:
student_name
age1
_marks
Invalid:
1age
student-name
class
7. Data Types
Python supports multiple built-in data types.
Numbers
a = 10
b = 15.5
c = 2+3j
Types:
Integer
Float
Complex
Strings
name = "Python"
Strings are immutable.
Lists
Ordered and mutable.
fruits = ["Apple", "Mango", "Orange"]
Tuples
Ordered but immutable.
marks = (80, 90, 95)
Sets
Unordered collection.
colors = {"Red", "Blue", "Green"}
Dictionaries
Key-value pairs.
student = {
"name":"Amit",
"Age":20,
"Course":"BCA"
}
8. Type Conversion
Python supports two types of conversion.
Implicit Conversion
Automatically performed.
a = 5
b = 2.5
print(a + b)
Output:
7.5
Explicit Conversion
Performed using functions.
age = "25"
new_age = int(age)
print(new_age)
Other functions:
int()
float()
str()
list()
tuple()
set()
9. Input and Output Functions
Input
name = input("Enter Name : ")
Output
print(name)
Example
name = input("Enter Name : ")
age = int(input("Enter Age : "))
print("Welcome", name)
print("Age =", age)
10. Comments and Documentation Strings
Single-line Comment
# This is a comment
Multi-line Comment
"""
This is
a multiline
comment
"""
Documentation String (Docstring)
def add(a,b):
"""
This function returns
sum of two numbers.
"""
return a+b
Docstrings help document code and are accessible through the __doc__ attribute or tools such as help().
11. Basic Operators
Arithmetic Operators
| Operator | Meaning |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
| // | Floor Division |
| ** | Exponent |
Example:
a = 10
b = 3
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
print(a//b)
print(a**b)
Relational Operators
| Operator | Meaning |
|---|---|
| == | Equal |
| != | Not Equal |
| > | Greater |
| < | Less |
| >= | Greater Equal |
| <= | Less Equal |
Logical Operators
| Operator | Meaning |
|---|---|
| and | Logical AND |
| or | Logical OR |
| not | Logical NOT |
Assignment Operators
| Operator | Example |
|---|---|
| = | x = 5 |
| += | x += 5 |
| -= | x -= 5 |
| *= | x *= 5 |
| /= | x /= 5 |
Bitwise Operators
| Operator | Meaning |
|---|---|
| & | AND |
| | | OR |
| ^ | XOR |
| ~ | NOT |
| << | Left Shift |
| >> | Right Shift |
Example:
a = 5
b = 3
print(a & b)
print(a | b)
print(a ^ b)
print(~a)
print(a << 1)
print(a >> 1)
Practical Activities
Activity 1: Research the History and Evolution of Python
Prepare a report including:
Creator of Python
Reasons for development
Major releases (1.0, 2.0, 3.0)
Current Python version
Future trends and applications
Activity 2: Install and Set Up Python Environments
Install any of the following:
Python IDLE
Anaconda
Jupyter Notebook
Visual Studio Code
Verify the installation by running:
print("Python Installed Successfully")
Activity 3: Program Demonstrating Variables, Data Types, and Operators
# Variables
name = "Alice"
age = 20
height = 5.4
# Data Types
print(type(name))
print(type(age))
print(type(height))
# Operators
a = 10
b = 5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Greater Than:", a > b)
print("Logical AND:", (a > 5) and (b < 10))
Activity 4: Interactive Python Script Using Input and Output
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello,", name)
print("You are", age, "years old.")
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Activity 5: Use Comments and Documentation Strings
"""
Program: Simple Calculator
Author: Student
Purpose: Demonstrate comments and docstrings.
"""
# Input two numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Calculate sum
result = num1 + num2
print("Sum =", result)
Activity 6: Perform Type Conversion
# String to Integer
num = "100"
integer_num = int(num)
# Integer to Float
float_num = float(integer_num)
# Float to String
string_num = str(float_num)
print("Original:", num, type(num))
print("Integer:", integer_num, type(integer_num))
print("Float:", float_num, type(float_num))
print("String:", string_num, type(string_num))
Summary
Python is a simple, powerful, and versatile programming language suitable for beginners and professionals alike. It has evolved significantly since its creation in 1989 and is now one of the leading languages in software development, artificial intelligence, data science, automation, and web development. Understanding Python's history, installation methods, syntax, variables, data types, operators, input/output functions, comments, and type conversion provides a strong foundation for learning advanced programming concepts.
Review Questions
Who developed Python and why was it created?
Explain the major milestones in the evolution of Python.
List any five features of Python.
Compare IDLE, Anaconda, Jupyter Notebook, and VS Code.
What is the importance of indentation in Python?
Differentiate between lists, tuples, sets, and dictionaries.
Explain implicit and explicit type conversion with examples.
Write a Python program demonstrating input, output, variables, and arithmetic operators.
What are documentation strings (docstrings), and why are they useful?
Differentiate between arithmetic, relational, logical, assignment, and bitwise operators with suitable examples.
Comments
Post a Comment